﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using canthovieclam.BL;
using canthovieclam.BL.DataContact.Enum;
using canthovieclam.BL.DataContact.Filter;
using canthovieclam.BL.Models;
using canthovieclam.Core.Utilities;
using canthovieclam.Models;

namespace canthovieclam.Controllers
{
    public class EmployerController : LayoutController
    {
        //
        // GET: /Employer/

        public ActionResult Index(EmployerModels employerModel)
        {
            return View();
        }

        //
        // GET: /Employer/Post
        [HttpGet]
        public ActionResult Post()
        {
            return View();
        }

        //
        // POST: /Employer/Post

        [HttpPost, ValidateInput(false)]
        public ActionResult Post(PostModels model)
        {
            PostJobImpl postJobImpl = new PostJobImpl();

            var jobModel = new JobModel
            {
                JobId = GuidUtils.NewSeqGuid(),
                JobTitle = model.JobTitle,
                JobDescription = model.JobDescription,
                EmployerId = postJobImpl.GetEmployerIdFromUserId((Guid)Membership.GetUser().ProviderUserKey)
            };

            postJobImpl.InsertToDatabase(jobModel, model.LocationId, model.CareerLevel, model.JobCatetoryId);
            return View(model);
        }

        //
        // GET: /Employer/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Employer/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Employer/Create

        [HttpPost]
        public ActionResult Create(EmployerModel employerModel)
        {
            try
            {
                var employerImpl = new EmployerImpl();

                // TODO: Add insert logic here
                employerModel.EmployerId = GuidUtils.NewSeqGuid();
                employerImpl.AddEmployer(employerModel);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Employer/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Employer/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Employer/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Employer/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
